Skip to content

Comments

[PW_SID:1056145] [v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1487

Closed
linux-riscv-bot wants to merge 1 commit intoworkflow__riscv__fixesfrom
pw1056145
Closed

[PW_SID:1056145] [v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core#1487
linux-riscv-bot wants to merge 1 commit intoworkflow__riscv__fixesfrom
pw1056145

Conversation

@linux-riscv-bot
Copy link

PR for series 1056145 applied to workflow__riscv__fixes

Name: [v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1056145
Version: 4

Currently, kvm_arch_vcpu_load() unconditionally restores guest CSRs and
HGATP. However, when a preempted VCPU is scheduled back on the same
physical CPU, and no other KVM VCPU has run on this CPU in the meantime,
the hardware CSRs are still valid.

This patch optimizes the vcpu_load path by skipping the expensive CSR
writes if all the following conditions are met:
1. The VCPU was previously preempted (vcpu->scheduled_out == 1).
2. It is being reloaded on the same CPU (vcpu->arch.last_exit_cpu == cpu).
3. No other VCPU used this CPU (vcpu == __this_cpu_read(kvm_former_vcpu)).
4. The CSRs are not dirty (!vcpu->arch.csr_dirty).

To ensure this fast-path doesn't break corner cases:
- Live migration and VCPU reset are naturally safe. KVM initializes
  last_exit_cpu to -1, which guarantees the fast-path won't trigger.
- A new 'csr_dirty' flag is introduced to track runtime userspace
  interventions. If userspace modifies guest configurations (e.g.,
  hedeleg via KVM_SET_GUEST_DEBUG, or CSRs via KVM_SET_ONE_REG) while
  the VCPU is preempted, the flag is set to skip fast path.

Note that kvm_riscv_vcpu_aia_load() is kept outside the skip logic
to ensure IMSIC/AIA interrupt states are always properly
synchronized.

Signed-off-by: Jinyu Tang <tjytimi@163.com>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 142.08 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1064.15 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1421.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 27.32 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 28.53 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 2.18 seconds
Result: WARNING
Output:

CHECK: Alignment should match open parenthesis
#81: FILE: arch/riscv/kvm/vcpu.c:590:
+	if (vcpu->scheduled_out && vcpu == __this_cpu_read(kvm_former_vcpu) &&
+		vcpu->arch.last_exit_cpu == cpu && !vcpu->arch.csr_dirty)

total: 0 errors, 0 warnings, 1 checks, 61 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit 3d52e2c0fb66 ("KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
total: 0 errors, 0 warnings, 1 checks, 61 lines checked
CHECK: Alignment should match open parenthesis


@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 85.30 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
kdoc
Desc: Detects for kdoc errors
Duration: 0.98 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
module-param
Desc: Detect module_param changes
Duration: 0.25 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 0.22 seconds
Result: PASS

@linux-riscv-bot
Copy link
Author

Patch 1: "[v4] KVM: riscv: Skip CSR restore if VCPU is reloaded on the same core"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.29 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot deleted the pw1056145 branch February 25, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants